<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML> 
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>字典管理</title>
	<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="../css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="../css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="../css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="../css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="../css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="../css/boot-crm.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
  <!-- 导航栏部分 -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation"
		 style="margin-bottom: 0">
	<div class="navbar-header">
		<a class="navbar-brand" href="<%=basePath%>customer/list.action">客户管理系统</a>
	</div>
	<!-- 导航栏右侧图标部分 -->
	<ul class="nav navbar-top-links navbar-right">
	    <!-- 邮件通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-envelope fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-messages">
				<li>
				    <a href="#">
						<div>
							<strong>张经理</strong> <span class="pull-right text-muted">
								<em>昨天</em>
							</span>
						</div>
						<div>今天晚上开会，讨论一下下个月工作的事...</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#">
				        <strong>查看全部消息</strong>
						<i class="fa fa-angle-right"></i>
				    </a>
				</li>
			</ul>
		</li>
		<!-- 邮件通知 end -->
		<!-- 任务通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
			    <i class="fa fa-tasks fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-tasks">
				<li>
				    <a href="#">
						<div>
							<p>
								<strong>任务 1</strong> 
								<span class="pull-right text-muted">完成40%</span>
							</p>
							<div class="progress progress-striped active">
								<div class="progress-bar progress-bar-success"
									role="progressbar" aria-valuenow="40" aria-valuemin="0"
									aria-valuemax="100" style="width: 40%">
									<span class="sr-only">完成40%</span>
								</div>
							</div>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<p>
								<strong>任务 2</strong> 
								<span class="pull-right text-muted">完成20%</span>
							</p>
							<div class="progress progress-striped active">
								<div class="progress-bar progress-bar-info" role="progressbar"
									aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"
									style="width: 20%">
									<span class="sr-only">完成20%</span>
								</div>
							</div>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#"> 
				        <strong>查看所有任务</strong>
						<i class="fa fa-angle-right"></i>
				    </a>
				</li>
			</ul> 
		</li>
		<!-- 任务通知 end -->
		<!-- 消息通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-bell fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-alerts">
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-comment fa-fw"></i> 新回复 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-envelope fa-fw"></i> 新消息 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-tasks fa-fw"></i> 新任务 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<i class="fa fa-upload fa-fw"></i> 服务器重启 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#"> 
				        <strong>查看所有提醒</strong>
						<i class="fa fa-angle-right"></i>
				    </a>
				</li>
			</ul> 
		</li>
		<!-- 消息通知 end -->
		<!-- 用户信息和系统设置 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-user fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-user">
				<li><a href="#"><i class="fa fa-user fa-fw"></i>
				               用户：${USER_SESSION.userName}
				    </a>
				</li>
				<li><a href="#"><i class="fa fa-gear fa-fw"></i> 系统设置</a></li>
				<li class="divider"></li>
				<li>
					<a href="${pageContext.request.contextPath }/logout.action">
					<i class="fa fa-sign-out fa-fw"></i>退出登录
					</a>
				</li>
			</ul> 
		</li>
		<!-- 用户信息和系统设置结束 -->
	</ul>
	<!-- 左侧显示列表部分 start-->
	<div class="navbar-default sidebar" role="navigation">
		<div class="sidebar-nav navbar-collapse">
			<ul class="nav" id="side-menu">
				<li class="sidebar-search">
					<div class="input-group custom-search-form">
						<input type="text" class="form-control" placeholder="查询内容...">
						<span class="input-group-btn">
							<button class="btn btn-default" type="button">
								<i class="fa fa-search" style="padding: 3px 0 3px 0;"></i>
							</button>
						</span>
					</div> 
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/customer/list.action" >
				      <i class="fa fa-edit fa-fw"></i> 客户管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/dict/list.action" class="active">
				      <i class="fa fa-dashboard fa-fw" ></i> 字典管理
				    </a>
				</li>
			</ul>
		</div>
	</div>
	<!-- 左侧显示列表部分 end--> 
  </nav>
    <!-- 字典列表查询部分  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">字典管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<div class="panel panel-default">
			<div class="panel-body">
				<form class="form-inline" method="post" 
				      action="${pageContext.request.contextPath }/dict/list.action">
					<div class="form-group">
						<label for="dictTypeName">字典类别名称</label> 
						<input type="text" class="form-control" id="dictTypeName" 
						                   value="${dictTypeName }" name="dictTypeName" />
					</div>
					<div class="form-group">
						<label for="dictItemName">字典状态</label> 
						<select	class="form-control" id="dictEnable" name="dictEnable">
						<!--  
						    <option value="">所有</option>
							<option value="${dictEnable }">可用</option>
							<option value="${dictEnable }">不可用</option>-->
							<option value=""> 所有 </option>
							<c:forEach items="${enableChange}" var="item">
								<option value="${item.number}"
								       <c:if test="${item.number == dictEnable}">selected</c:if>>
								    ${item.state }
								</option>
							</c:forEach>
						</select>
					</div>
					<button type="submit" class="btn btn-primary">查询</button>
				</form>
			</div>
		</div>
		<a href="#" class="btn btn-primary" data-toggle="modal" 
		           data-target="#newCustomerDialog" onclick="clearCustomer()">新建</a>
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">字典信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>字典主键</th>
								<th>字典类别代码</th>
								<th>字典类别名称</th>
								<th>字典项目名称</th>
								<th>字典项目代码</th>
								<th>排序字段</th>
								<th>状态</th>
								<th>备注</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.rows}" var="row">
								<tr>
									<td>${row.dictId}</td>
									<td>${row.dictTypeCode}</td>
									<td>${row.dictTypeName}</td>
									<td>${row.dictItemName}</td>
									<td>${row.dictItemCode}</td>
									<td>${row.dictSort}</td>
								    <td>${row.dictEnable}</td>
								    <td>${row.dictMemo}</td>
									<td>
										<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#customerEditDialog" onclick= "editDict(${row.dictId})">修改</a>
										<a href="#" class="btn btn-danger btn-xs" onclick="changeState(${row.dictId})">状态反转</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<ujn:page url="${pageContext.request.contextPath }/dict/list.action" bean="page" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>
	<!-- 字典列表查询部分  end-->
</div>

<!-- 创建字典模态框 -->
<div class="modal fade" id="newCustomerDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel" >新建字典信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="new_dict_form">
					
					<div class="form-group">
						<label for="new_dictTypeName" style="float:left;padding:7px 15px 0 27px;">字典类型</label> 
						<div class="col-sm-10">
				            <input type="url"  list = "url_list" class="form-control" id="new_dictTypeName" name="dictTypeName" placeholder="请输入新类型或选取已有类型"/>
						<datalist id="url_list"> 

                                <c:forEach items="${dictType}" var="item">
									<option value="${item.dictTypeName}"<c:if test="${item.dictTypeName== dictTypeName}">selected</c:if>>
									${item.dictTypeName }						
									</option>
								</c:forEach>
						</datalist>
						<!-- <select	class="form-control" id="new_dictItemName" name="dictTypeName">
								<option value="">--请选择--</option>
								<c:forEach items="${dictType}" var="item">
									<option value="${item.dictTypeName}"<c:if test="${item.dictTypeName== dictItemType}">selected</c:if>>
									${item.dictTypeName }									
									</option>
								</c:forEach>
							</select> -->
						</div>
					</div>
					<div class="form-group">
						<label for="new_dictItemName" class="col-sm-2 control-label">字典名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_dictItemName" placeholder="字典名称" name="dictItemName" />
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="createNewDict()">新建字典信息</button>
			</div>
		</div>
	</div>
</div>
<!-- 修改客户模态框 -->

<div class="modal fade" id="customerEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改字典名称</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_baseDict_form">
					<input type="hidden" id="edit_dictId" name="dictId"/>
					<div class="form-group">
						<label for="edit_dictType" class="col-sm-2 control-label">字典类型</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_dictTypeName" placeholder="读取字典类型" name="dictTypeName" disabled/>
						</div>
					</div>
					<div class="form-group">
						<label for="edit_dictName" class="col-sm-2 control-label">字典名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_dictItemName" placeholder="读取字典名称" name="dictItemName" />
						</div>
					</div>
					
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateNewDict()">保存修改</button>
			</div>
		</div>
	</div>
</div>
<!-- 引入js文件 -->
<!-- jQuery -->
<script src="../js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="../js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="../js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="../js/jquery.dataTables.min.js"></script>
<script src="../js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="../js/sb-admin-2.js"></script>
<!-- 编写js代码 -->
<script type="text/javascript">
//全局变量
var old_cus = null;
//清空新建客户窗口中的数据
function clearCustomer() {
    $("#new_dictTypeName").val("");
    $("#new_dictItemName").val("");
}
// 创建新字典
function createNewDict() {
$.post("<%=basePath%>dict/create.action",
$("#new_dict_form").serialize(),function(data){
        if(data =="OK"){
            alert("字典创建成功！");
            window.location.reload();
        }else{
            alert("字典创建失败！");
            window.location.reload();
        }
    });
}

//获取修改数据操作
function editDict(dictId) {
	 $.ajax({
	        type:"get",
	        url:"<%=basePath%>dict/getBaseDictById.action",
	        data:{"dictId":dictId},
	        success:function(data) {
	        	//存储数据
	        	old_base = data;
	        	console.log(old_base);
	        	$("#edit_dictId").val(data.dictId);
	            $("#edit_dictItemName").val(data.dictItemName);
	            $("#edit_dictTypeName").val(data.dictTypeName);
	        }
	    });
}
//执行修改字典信息
function updateNewDict(){
	//取出全局变量中用到的数据
	let old_base_json = {
			"dictItemName": old_base.dictItemName,
			"dictTypeName": old_base.dictTypeName
	}
		//取出表单数据
    let new_base_json = {
			"dictItemName": $("#edit_dictItemName").val(),
			"dictTypeName": $("#edit_dictTypeName").val()
			
    }
    //判断是否进行了修改
	if (JSON.stringify(old_base_json) == JSON.stringify(new_base_json)){
		alert("未做任何修改");
		return false;
	} else {
		$.post("<%=basePath%>dict/update.action",$("#edit_baseDict_form").serialize(),
				function(data){
				 if(data =="OK"){
		                alert("字典修改成功！");
		                window.location.reload();
		            }else if(data=="NO"){
		                alert("修改字典失败！");
		                window.location.reload();
		            }
		            
				});
			}
}


// 状态反转
function changeState(dictId) {
    if(confirm('确实要进行状态反转吗?')) {
    $.post("<%=basePath%>dict/change.action",{"dictId":dictId},
function(data){
    	if(data =="OK"){
    	 alert("字典修改成功！");
         window.location.reload();
     }
    	else {
         alert("修改字典失败！");
         window.location.reload();
     }
    
        });
    }
}
</script>
</body>
</html>